﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.AutoId
{
    public class AutoIDPresenter : Presenter<IAutoIDView>
    {
        public AutoIDPresenter(IAutoIDView view)
            : base(view)
        {
        }

        public void Display(string autoId)
        {
            //if (autoId == null) return;

            //var autoID = Model.GetAutoID(autoId);

            //View.AutoId = autoID.AutoId;
            //View.RefTypeID = autoID.RefTypeID;
            //View.RefTypeName = autoID.RefTypeName;
            //View.Prefix = autoID.Prefix;
            //View.Value = autoID.Value;
            //View.LengthOfValue = autoID.LengthOfValue;
            //View.Suffix = autoID.Suffix;
            //View.RestaurantID = autoID.RestaurantID;
        }

        public void DisplayByRefType(int refType)
        {
            if (refType == 0) return;

            var autoID = Model.GetAutoIDByRefType(refType);

            View.AutoId = autoID.AutoId;
            View.Prefix = autoID.Prefix;
            View.Value = autoID.Value;
            View.LengthOfValue = autoID.LengthOfValue;
            View.Suffix = autoID.Suffix;
        }

        public int Save()
        {
            var autoId = new AutoIDModel
            {
                AutoId = View.AutoId,
                Prefix = View.Prefix,
                Value = View.Value,
                LengthOfValue = View.LengthOfValue,
                Suffix = View.Suffix,
            };

            if (View.AutoId == null) { return 0; }
            else
                return Model.UpdateAutoID(autoId);
        }

        //public int Delete(string districtCode)
        //{
        //    return Model.DeleteDistrict(districtCode);
        //}
    }
}
